import { Module } from 'vuex'
import {
  getCategorygoodsCount,
  getCategorygoodsSale,
  getCategorygoodsFavor,
  getCategoryAddressSale
} from '../../../service/main/analysis/dashboard'

import { IRootState } from '../../type'
import { IDashboardState } from './types'
const dashboardModule: Module<IDashboardState, IRootState> = {
  namespaced: true,
  state() {
    return {
      categoryGoodsCount: [],
      categoryGoodsSale: [],
      categoryGoodsFavor: [],
      addressGoodsSale: []
    }
  },
  mutations: {
    changeCategoryGoodsCount(state, list) {
      state.categoryGoodsCount = list
    },
    changeCategoryGoodsSale(state, list) {
      state.categoryGoodsSale = list
    },
    changeCategoryGoodsFavor(state, list) {
      state.categoryGoodsFavor = list
    },
    changeAddressGoodsSale(state, list) {
      state.addressGoodsSale = list
    }
  },
  actions: {
    async getDashboardDataAction({ commit }) {
      const categoryCountRes = await getCategorygoodsCount()
      const { data: countList } = categoryCountRes as any
      commit('changeCategoryGoodsCount', countList)
      const categorySaletRes = await getCategorygoodsSale()
      const { data: saleList } = categorySaletRes as any
      commit('changeCategoryGoodsSale', saleList)
      const categoryFavorRes = await getCategorygoodsFavor()
      const { data: favorList } = categoryFavorRes as any
      commit('changeCategoryGoodsFavor', favorList)
      const categoryAddressRes = await getCategoryAddressSale()
      const { data: addressList } = categoryAddressRes as any
      commit('changeAddressGoodsSale', addressList)
    }
  }
}

export default dashboardModule
